﻿


using System;
using Demo.Infrastructure;
using Demo.Domain;
using Demo.ServiceContracts;
using Demo.Repository;
using Demo.DataObjects;
using AutoMapper;

namespace Demo.Application
{
    public class ActionServiceImpl : IActionService 
    {
        private readonly IActionRepository actionRepository = ServiceLocator.Instance.GetService<IActionRepository>();


        public void CreateAction(string name, int moduleId, int sort = 0)
        {
            actionRepository.CreateAction(name, moduleId, sort);
        }

        public ActionDTO GetActionDTOWithName(string name)
        {
            var obj = actionRepository.GetActionWithName(name);
            return Mapper.Map <ActionDTO>(obj);
        }

        public ActionDTO GetModuleDTOWithId(int id)
        {
            var obj = actionRepository.GetActionWithId(id);
            return Mapper.Map<ActionDTO>(obj);
        }

        public System.Collections.Generic.IList<ActionDTO> GetActionDTOWithUserId(int userid)
        {
            var list = actionRepository.GetActionWithUserId(userid);
            return Mapper.Map<System.Collections.Generic.List<ActionDTO>>(list);
        }

        public System.Collections.Generic.IList<ActionDTO> GetActionDTO()
        {
            var list = actionRepository.GetAction();
            return Mapper.Map<System.Collections.Generic.List<ActionDTO>>(list);
        }

        public bool ChangeActionWithName(string oldName, string newName)
        {
            return actionRepository.ChangeActionWithName(oldName, newName);
        }

        //public bool ChangeActionWithName(string Name,int newModuleId)
        //{
        //    return actionRepository.ChangeActionWithName(Name, newModuleId);
        //}
    }
}
